//类
class C1 {
    name: string;

    constructor(n: string) {
        this.name = n
    }

    getName(): string {
        return this.name
    }
}

let cc1 = new C1("名字")
console.log(cc1.getName())


//继承
class Class1 {
    num: number = 123;

    getNum(): number {
        return this.num;
    }
}

class Class2 extends Class1 {
    age: number = 18;

    getAge(): number {
        return this.age;
    }

    constructor() {
        super();
        console.log("super.getNum=", super.getNum())
    }
}

let cc2 = new Class2()
console.log(cc2.getAge(), cc2.getNum())


// 方法默认值
function f(n: number = 12) {

}


// 公共，私有与受保护的修饰符
class Animal {
    public name: string;
    private age: number;
    protected num: number;

    public constructor(theName: string, theAge: number, theNumber: number) {
        this.name = theName;
        this.age = theAge
        this.num = theNumber
    }

    public move(distanceInMeters: number) {
        console.log(`${this.name} moved ${distanceInMeters}m.`);
    }
}

let anml = new Animal("Cat", 2, 111);
let name11 = anml.name
// let age = anml.age // 错误: 'age' 是私有的.
// let num11 = anml.num // 错误
console.log(name11)


// protected
class Person {
    protected name: string;

    protected constructor(theName: string) {
        this.name = theName;
    }
}

// Employee 能够继承 Person
class Employee extends Person {
    private department: string;

    constructor(name: string, department: string) {
        super(name);
        this.department = department;
    }

    public getElevatorPitch() {
        return `Hello, my name is ${this.name} and I work in ${this.department}.`;
    }
}

let howard = new Employee("Howard", "Sales");
// let john = new Person("John"); // 错误: 'Person' 的构造函数是被保护的.


// 存取器

class Class {
    private name?: string;

    setName(n: string) {
        this.name = n
    }

    getName() {
        return this.name;
    }
}

let c111 = new Class();
c111.setName("零三")
console.log(c111.getName())

// 抽象类
abstract class absClass1 {
    constructor(public name: string) {
    }

    printName(): void {
        console.log('Department name: ' + this.name);
    }

    abstract printMeeting(): void; // 必须在派生类中实现
}

class C123 extends absClass1 {
    printMeeting(): void {
        console.log(this.name)
    }
}

const c123:C123 = new C123("零三")
c123.printMeeting()


// 静态属性
class C1234 {
    static name1:string = "零三03";
    getName () {
        return C1234.name1;
    }
}
C1234.name1 = "零三003"
console.log(C1234.name1)
const c1234:C1234 = new C1234()
console.log(c1234.getName())

// 把类当作接口使用
class Point {
    x1?: number;
    y1?: number;
}

interface Point3d extends Point {
    z1: number;
}

let point3d: Point3d = {x1: 1, y1: 2, z1: 3};
console.log(point3d)












